package com.example.tests;

import java.io.FileReader;
import java.util.Properties;
import java.util.logging.Logger;

import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;

import com.example.fw.ApplicationManager;

public class TestBase {

	protected ApplicationManager manager;
	protected Logger log = Logger.getLogger("TEST");
	
	@BeforeClass
	@Parameters ({"configFile", "uimapFile"})
	public void setUp(@Optional String configFile, @Optional String uimapFile) throws Exception {		
		log.info("Start manager");
		if (configFile == null) configFile = System.getProperty("configProperty");
		if (configFile == null) configFile = System.getenv("configProperty");
		if (configFile == null) configFile = "application.properties";

		if (uimapFile == null) uimapFile = System.getProperty("uimapProperty");
		if (uimapFile == null) uimapFile = System.getenv("uimapProperty");
		if (uimapFile == null) uimapFile = "uimap.properties";
		
		Properties props = new Properties();
		props.load(new FileReader(configFile));
		props.load(new FileReader(uimapFile));
		manager = ApplicationManager.getInstance();
		manager.setProperties(props);
	}

	@AfterTest
	public void tearDown() throws Exception {
		log.info("Stop manager");
		ApplicationManager.getInstance().stop();
	}
}
